#ifndef	___SERVICE_IMP_NETWORK___
#define	___SERVICE_IMP_NETWORK___


#include "Service/ServiceImp.h"
#include "Entry/LibExportCli.h"
#include "Service/Session.h"
#include "Message/MsgBuilderIf.h"

//
//	Network Service for client
//
//
class TCLI_API ServiceImpNW : public ServiceImp, public Session
{
public:

	ServiceImpNW();
	virtual ~ServiceImpNW();

	//
	//	initialize service
	//
	virtual void init(ServiceData& data);

	//
	//	session start & end
	//
	virtual void onSessionStart(const boost::system::error_code& error,  boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
	virtual void onSessionEnd();
protected:
	virtual void onStart();
	virtual void onStop();
	//
	//	callbacks
	//
	virtual void onTimer();
	virtual void onDispatchMsg(IMsg* pMsg);

	//
	//	data on connections
	//
	void onInput(const boost::system::error_code& error, size_t bytes_transferred, MsgBuffer* buffer );
	void onOutput(const boost::system::error_code& error, size_t bytes_transferred, MsgBuffer* buffer );
protected:
	void autoReconnect();

	boost::asio::io_service::work	m_theEmptyWork;
	boost::asio::ip::tcp::resolver	m_theResolver;
	boost::asio::ip::tcp::endpoint	m_theEndPoint;


	Service*	m_wpSvcLgc;

	MsgBufferFactory	m_theMsgBuffFact;
	IMsgBuilder*		m_pMsgBuilder;

	string		m_strSvrIP;
	string		m_strSvrPort;

	bool		m_bConnected;
};

#endif
